var p = 0, c = 0, d = 0
var api = require('../../utils/api.js')
var area = require('../../utils/area.js')
Page({
    data: {
        stages: [],
        stageSelIndex: '',
        station: [],
        stationSelIndex: '',

        result: [],
        id: 0
    },
    onLoad:function(options){
        this.setData({ id: options.id });
        this.setEdit();
    },
    setEdit: function(e) {
        if (this.data.id>0) {
            api.post({
                url: 'user/address/read',
                data: {'id':this.data.id},
                success: res => {
                    if (res.code == 1) {
                        var detail = res.data;
                        this.setData({ 
                            result: detail,
                            countryEnabled: false
                        });
                    }
                }
            });
        }
    },
    codeCopy(e){
        console.log(e);
        wx.setClipboardData({
            data: e.currentTarget.dataset.msg,  //+this.data.result.fin_code
            success: function(res) {
                wx.getClipboardData({
                    success: function(res) {
                        wx.showToast({
                            title: '复制成功',
                            icon: 'success',
                            duration: 800
                        })
                    }
                })
            }
        })
        // var detail = e.detail;
        // api.post({
        //     url: 'user/address/update',
        //     data: {form_id: detail.formId},
        //     success: res => {
                
        //     }
        // });
    },
    delAddr(e){
        var del_id = this.data.id;
        wx.showModal({
            content: '是否确认删除？',
            showCancel: true,
            success: function (res) {
                if (res.confirm) {
                    api.post({
                        url: 'user/address/delete',
                        data: {'id':del_id},
                        success: data => {
                            if (data.code == 1) {
                                wx.showToast({
                                    title: data.msg,
                                    icon: 'success',
                                    duration: 800
                                })
                                setTimeout(function(){ wx.switchTab({ url: '/pages/my/address'}); }, 800);
                            }
                        }
                    });
                }
            }
        })
    },
});